<?php

	// TITLE: Schedule AUTO MODEL
	// FILE: scaffolding/model/schedule.php
	// AUTHOR: AUTOGEN
	// CREATED: 2015/04/20 07:49:57
	// DESCRIPTION: 
	// REQUIREMENTS: 

	$createSchedule = function($con, $schedule) {
		$sql = 'INSERT INTO schedule (id, volunteer_id, event_detail_id, description, hours_scheduled, hours_actual, when_entered, who_entered, when_authorized, who_authorized) VALUES (';
		$sql .= $schedule->getId() . ', ';
		$sql .= $schedule->getVolunteerId() . ', ';
		$sql .= $schedule->getEventDetailId() . ', ';
		$sql .= $schedule->getDescription() . ', ';
		$sql .= $schedule->getHoursScheduled() . ', ';
		$sql .= $schedule->getHoursActual() . ', ';
		$sql .= $schedule->getWhenEntered() . ', ';
		$sql .= $schedule->getWhoEntered() . ', ';
		$sql .= $schedule->getWhenAuthorized() . ', ';
		$sql .= $schedule->getWhoAuthorized() . ')';
		$sql .= ')';
		$result = mysqli_query($con, $sql);
		$id = ($result) ? mysqli_insert_id($con) : $result;
		mysqli_close($con);
		return $id;
	};

	$readSchedule = function($con, $id) {
		$sql = 'SELECT * FROM schedule WHERE id = ' . $id;
		$results = mysqli_query($con, $sql);
		mysqli_close($con);
		if ($results) {
			$result = mysqli_fetch_array($results);
			$schedule = new Schedule();
			$schedule->setId(result[0]);
			$schedule->setVolunteerId($dbio->select($readVolunteer(result[1])));
			$schedule->setEventDetailId($dbio->select($readEventDetail(result[2])));
			$schedule->setDescription(result[3]);
			$schedule->setHoursScheduled(result[4]);
			$schedule->setHoursActual(result[5]);
			$schedule->setWhenEntered(result[6]);
			$schedule->setWhoEntered(result[7]);
			$schedule->setWhenAuthorized(result[8]);
			$schedule->setWhoAuthorized(result[9]);
		} else {
			$schedule = false;
		}
		return $schedule;
	};

	$updateSchedule = function($con, $schedule) {
		$sql = 'UPDATE schedule SET ';
		$sql .= 'id = ' . $schedule->getId() . ', ';
		$sql .= 'volunteer_id = ' . $schedule->getVolunteerId() . ', ';
		$sql .= 'event_detail_id = ' . $schedule->getEventDetailId() . ', ';
		$sql .= 'description = ' . $schedule->getDescription() . ', ';
		$sql .= 'hours_scheduled = ' . $schedule->getHoursScheduled() . ', ';
		$sql .= 'hours_actual = ' . $schedule->getHoursActual() . ', ';
		$sql .= 'when_entered = ' . $schedule->getWhenEntered() . ', ';
		$sql .= 'who_entered = ' . $schedule->getWhoEntered() . ', ';
		$sql .= 'when_authorized = ' . $schedule->getWhenAuthorized() . ', ';
		$sql .= 'who_authorized = ' . $schedule->getWhoAuthorized() ;
		$sql .= 'WHERE id = ' . id;
		$result = mysqli_query($con, $sql);
		mysqli_close($con);
		return $result;
	};

	$deleteSchedule = function($con, $id) {
		$sql = 'DELETE FROM schedule WHERE id = ' . $id;
		$result = mysqli_query($con, $sql);
		mysqli_close($con);
		return $result;
	};

	$listSchedule = function($con) {
		$sql = 'SELECT * FROM schedule';
		$results = mysqli_query($con, $sql);
		mysqli_close($con);
		if ($results) {
			$schedules = array();
			while ($result = mysqli_fetch_array($results)) {
				$schedule = new Schedule();
				$schedule->setId(result[0]);
				$schedule->setVolunteerId($dbio->select($readVolunteer(result[1])));
				$schedule->setEventDetailId($dbio->select($readEventDetail(result[2])));
				$schedule->setDescription(result[3]);
				$schedule->setHoursScheduled(result[4]);
				$schedule->setHoursActual(result[5]);
				$schedule->setWhenEntered(result[6]);
				$schedule->setWhoEntered(result[7]);
				$schedule->setWhenAuthorized(result[8]);
				$schedule->setWhoAuthorized(result[9]);
				$schedules[] = schedule;
			}// end while
		} else {
			$schedules = false;
		}
		return $schedules;
	};

